home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / cygwinccompiler.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  10KB  |  281 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''distutils.cygwinccompiler
  5.  
  6. Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
  7. handles the Cygwin port of the GNU C compiler to Windows.  It also contains
  8. the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
  9. cygwin in no-cygwin mode).
  10. '''
  11. __revision__ = '$Id: cygwinccompiler.py 73349 2009-06-11 09:17:19Z tarek.ziade $'
  12. import os
  13. import sys
  14. import copy
  15. from distutils.ccompiler import gen_preprocess_options, gen_lib_options
  16. from distutils.unixccompiler import UnixCCompiler
  17. from distutils.file_util import write_file
  18. from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
  19. from distutils import log
  20.  
  21. def get_msvcr():
  22.     '''Include the appropriate MSVC runtime library if Python was built
  23.     with MSVC 7.0 or later.
  24.     '''
  25.     msc_pos = sys.version.find('MSC v.')
  26.     if msc_pos != -1:
  27.         msc_ver = sys.version[msc_pos + 6:msc_pos + 10]
  28.         if msc_ver == '1300':
  29.             return [
  30.                 'msvcr70']
  31.         if msc_ver == '1310':
  32.             return [
  33.                 'msvcr71']
  34.         if msc_ver == '1400':
  35.             return [
  36.                 'msvcr80']
  37.         if msc_ver == '1500':
  38.             return [
  39.                 'msvcr90']
  40.         raise ValueError('Unknown MS Compiler version %s ' % msc_ver)
  41.     msc_pos != -1
  42.  
  43.  
  44. class CygwinCCompiler(UnixCCompiler):
  45.     compiler_type = 'cygwin'
  46.     obj_extension = '.o'
  47.     static_lib_extension = '.a'
  48.     shared_lib_extension = '.dll'
  49.     static_lib_format = 'lib%s%s'
  50.     shared_lib_format = '%s%s'
  51.     exe_extension = '.exe'
  52.     
  53.     def __init__(self, verbose = 0, dry_run = 0, force = 0):
  54.         UnixCCompiler.__init__(self, verbose, dry_run, force)
  55.         (status, details) = check_config_h()
  56.         self.debug_print("Python's GCC status: %s (details: %s)" % (status, details))
  57.         if status is not CONFIG_H_OK:
  58.             self.warn("Python's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros." % details)
  59.         
  60.         (self.gcc_version, self.ld_version, self.dllwrap_version) = get_versions()
  61.         self.debug_print(self.compiler_type + ': gcc %s, ld %s, dllwrap %s\n' % (self.gcc_version, self.ld_version, self.dllwrap_version))
  62.         if self.ld_version >= '2.10.90':
  63.             self.linker_dll = 'gcc'
  64.         else:
  65.             self.linker_dll = 'dllwrap'
  66.         if self.ld_version >= '2.13':
  67.             shared_option = '-shared'
  68.         else:
  69.             shared_option = '-mdll -static'
  70.         self.set_executables(compiler = 'gcc -mcygwin -O -Wall', compiler_so = 'gcc -mcygwin -mdll -O -Wall', compiler_cxx = 'g++ -mcygwin -O -Wall', linker_exe = 'gcc -mcygwin', linker_so = '%s -mcygwin %s' % (self.linker_dll, shared_option))
  71.         if self.gcc_version == '2.91.57':
  72.             self.dll_libraries = [
  73.                 'msvcrt']
  74.             self.warn('Consider upgrading to a newer version of gcc')
  75.         else:
  76.             self.dll_libraries = get_msvcr()
  77.  
  78.     
  79.     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
  80.         if ext == '.rc' or ext == '.res':
  81.             
  82.             try:
  83.                 self.spawn([
  84.                     'windres',
  85.                     '-i',
  86.                     src,
  87.                     '-o',
  88.                     obj])
  89.             except DistutilsExecError:
  90.                 msg = None
  91.                 raise CompileError, msg
  92.             except:
  93.                 None<EXCEPTION MATCH>DistutilsExecError
  94.             
  95.  
  96.         None<EXCEPTION MATCH>DistutilsExecError
  97.         
  98.         try:
  99.             self.spawn(self.compiler_so + cc_args + [
  100.                 src,
  101.                 '-o',
  102.                 obj] + extra_postargs)
  103.         except DistutilsExecError:
  104.             msg = None
  105.             raise CompileError, msg
  106.  
  107.  
  108.     
  109.     def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
  110.         if not extra_preargs:
  111.             pass
  112.         extra_preargs = copy.copy([])
  113.         if not libraries:
  114.             pass
  115.         libraries = copy.copy([])
  116.         if not objects:
  117.             pass
  118.         objects = copy.copy([])
  119.         libraries.extend(self.dll_libraries)
  120.         if export_symbols is not None:
  121.             if target_desc != self.EXECUTABLE or self.linker_dll == 'gcc':
  122.                 temp_dir = os.path.dirname(objects[0])
  123.                 (dll_name, dll_extension) = os.path.splitext(os.path.basename(output_filename))
  124.                 def_file = os.path.join(temp_dir, dll_name + '.def')
  125.                 lib_file = os.path.join(temp_dir, 'lib' + dll_name + '.a')
  126.                 contents = [
  127.                     'LIBRARY %s' % os.path.basename(output_filename),
  128.                     'EXPORTS']
  129.                 for sym in export_symbols:
  130.                     contents.append(sym)
  131.                 
  132.                 self.execute(write_file, (def_file, contents), 'writing %s' % def_file)
  133.                 if self.linker_dll == 'dllwrap':
  134.                     extra_preargs.extend([
  135.                         '--output-lib',
  136.                         lib_file])
  137.                     extra_preargs.extend([
  138.                         '--def',
  139.                         def_file])
  140.                 else:
  141.                     objects.append(def_file)
  142.             
  143.         if not debug:
  144.             extra_preargs.append('-s')
  145.         
  146.         UnixCCompiler.link(self, target_desc, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, None, debug, extra_preargs, extra_postargs, build_temp, target_lang)
  147.  
  148.     
  149.     def object_filenames(self, source_filenames, strip_dir = 0, output_dir = ''):
  150.         if output_dir is None:
  151.             output_dir = ''
  152.         
  153.         obj_names = []
  154.         for src_name in source_filenames:
  155.             (base, ext) = os.path.splitext(os.path.normcase(src_name))
  156.             if ext not in self.src_extensions + [
  157.                 '.rc',
  158.                 '.res']:
  159.                 raise UnknownFileError, "unknown file type '%s' (from '%s')" % (ext, src_name)
  160.             ext not in self.src_extensions + [
  161.                 '.rc',
  162.                 '.res']
  163.             if strip_dir:
  164.                 base = os.path.basename(base)
  165.             
  166.             if ext == '.res' or ext == '.rc':
  167.                 obj_names.append(os.path.join(output_dir, base + ext + self.obj_extension))
  168.                 continue
  169.             obj_names.append(os.path.join(output_dir, base + self.obj_extension))
  170.         
  171.         return obj_names
  172.  
  173.  
  174.  
  175. class Mingw32CCompiler(CygwinCCompiler):
  176.     compiler_type = 'mingw32'
  177.     
  178.     def __init__(self, verbose = 0, dry_run = 0, force = 0):
  179.         CygwinCCompiler.__init__(self, verbose, dry_run, force)
  180.         if self.ld_version >= '2.13':
  181.             shared_option = '-shared'
  182.         else:
  183.             shared_option = '-mdll -static'
  184.         if self.gcc_version <= '2.91.57':
  185.             entry_point = '--entry _DllMain@12'
  186.         else:
  187.             entry_point = ''
  188.         self.set_executables(compiler = 'gcc -mno-cygwin -O -Wall', compiler_so = 'gcc -mno-cygwin -mdll -O -Wall', compiler_cxx = 'g++ -mno-cygwin -O -Wall', linker_exe = 'gcc -mno-cygwin', linker_so = '%s -mno-cygwin %s %s' % (self.linker_dll, shared_option, entry_point))
  189.         self.dll_libraries = []
  190.         self.dll_libraries = get_msvcr()
  191.  
  192.  
  193. CONFIG_H_OK = 'ok'
  194. CONFIG_H_NOTOK = 'not ok'
  195. CONFIG_H_UNCERTAIN = 'uncertain'
  196.  
  197. def check_config_h():
  198.     '''Check if the current Python installation (specifically, pyconfig.h)
  199.     appears amenable to building extensions with GCC.  Returns a tuple
  200.     (status, details), where \'status\' is one of the following constants:
  201.       CONFIG_H_OK
  202.         all is well, go ahead and compile
  203.       CONFIG_H_NOTOK
  204.         doesn\'t look good
  205.       CONFIG_H_UNCERTAIN
  206.         not sure -- unable to read pyconfig.h
  207.     \'details\' is a human-readable string explaining the situation.
  208.  
  209.     Note there are two ways to conclude "OK": either \'sys.version\' contains
  210.     the string "GCC" (implying that this Python was built with GCC), or the
  211.     installed "pyconfig.h" contains the string "__GNUC__".
  212.     '''
  213.     sysconfig = sysconfig
  214.     import distutils
  215.     import string as string
  216.     if string.find(sys.version, 'GCC') >= 0:
  217.         return (CONFIG_H_OK, "sys.version mentions 'GCC'")
  218.     fn = sysconfig.get_config_h_filename()
  219.     
  220.     try:
  221.         f = open(fn)
  222.         s = f.read()
  223.         f.close()
  224.     except IOError:
  225.         string.find(sys.version, 'GCC') >= 0
  226.         exc = string.find(sys.version, 'GCC') >= 0
  227.         return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror))
  228.  
  229.     if string.find(s, '__GNUC__') >= 0:
  230.         return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn)
  231.     return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
  232.  
  233.  
  234. def get_versions():
  235.     ''' Try to find out the versions of gcc, ld and dllwrap.
  236.         If not possible it returns None for it.
  237.     '''
  238.     LooseVersion = LooseVersion
  239.     import distutils.version
  240.     find_executable = find_executable
  241.     import distutils.spawn
  242.     import re as re
  243.     gcc_exe = find_executable('gcc')
  244.     if gcc_exe:
  245.         out = os.popen(gcc_exe + ' -dumpversion', 'r')
  246.         out_string = out.read()
  247.         out.close()
  248.         result = re.search('(\\d+\\.\\d+(\\.\\d+)*)', out_string)
  249.         if result:
  250.             gcc_version = LooseVersion(result.group(1))
  251.         else:
  252.             gcc_version = None
  253.     else:
  254.         gcc_version = None
  255.     ld_exe = find_executable('ld')
  256.     if ld_exe:
  257.         out = os.popen(ld_exe + ' -v', 'r')
  258.         out_string = out.read()
  259.         out.close()
  260.         result = re.search('(\\d+\\.\\d+(\\.\\d+)*)', out_string)
  261.         if result:
  262.             ld_version = LooseVersion(result.group(1))
  263.         else:
  264.             ld_version = None
  265.     else:
  266.         ld_version = None
  267.     dllwrap_exe = find_executable('dllwrap')
  268.     if dllwrap_exe:
  269.         out = os.popen(dllwrap_exe + ' --version', 'r')
  270.         out_string = out.read()
  271.         out.close()
  272.         result = re.search(' (\\d+\\.\\d+(\\.\\d+)*)', out_string)
  273.         if result:
  274.             dllwrap_version = LooseVersion(result.group(1))
  275.         else:
  276.             dllwrap_version = None
  277.     else:
  278.         dllwrap_version = None
  279.     return (gcc_version, ld_version, dllwrap_version)
  280.  
  281.